import React, { Component } from "react";
import { CountContext } from "./App";
import { Consumer as Consumer2 } from "./Child1";

// const { Consumer } = createContext();

class Child2 extends Component {
  state = {};
  // Consumer用于子组件里面做接受
  // 这个组件里面可以写一个函数，函数有一个value参数
  render() {
    return (
      <div>
        这是child2组件 -{" "}
        <CountContext.Consumer>
          {(value) => <span>{value.num}</span>}
        </CountContext.Consumer>
        <Consumer2>{(value) => <span>{value.name}</span>}</Consumer2>
      </div>
    );
  }
}

export default Child2;
